package com.czwj.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.czwj.annotation.SystemControllerLog;
import com.czwj.entities.BudgetExecute;
import com.czwj.entities.BudgetMain;
import com.czwj.entities.BudgetSubItem;
import com.czwj.entities.CapitalApply;
import com.czwj.entities.DataGridData;
import com.czwj.entities.Form;
import com.czwj.entities.Goods;
import com.czwj.entities.GoodsCurrent;
import com.czwj.entities.OperateResult;
import com.czwj.entities.PageBean;
import com.czwj.entities.PlanDaily;
import com.czwj.entities.PlanMain;
import com.czwj.entities.ProjectItem;
import com.czwj.entities.Quantities;
import com.czwj.entities.Review;
import com.czwj.entities.UrgentApply;
import com.czwj.entities.UserInfo;
import com.czwj.entities.Notice;
import com.czwj.service.BudgetExecuteService;
import com.czwj.service.BudgetItemService;
import com.czwj.service.BudgetMainService;
import com.czwj.service.BudgetSubItemService;
import com.czwj.service.CapitalApplyService;
import com.czwj.service.FinishApplyService;
import com.czwj.service.FormService;
import com.czwj.service.GoodsCurrentService;
import com.czwj.service.GoodsService;
import com.czwj.service.NoticeService;
import com.czwj.service.PlanDailyService;
import com.czwj.service.PlanMainService;
import com.czwj.service.ProjectItemService;
import com.czwj.service.QuantitiesService;
import com.czwj.service.ReviewService;
import com.czwj.service.UrgentApplyService;
import com.czwj.util.TextUtil;
import com.czwj.util.WechatUtil;
import net.sf.json.JSONObject;

@Controller
public class ReviewAction{
	@Resource
	ReviewService reviewService;
	
	@Resource
	PlanMainService planMainService;
	
	@Resource
	PlanDailyService planDailyService;
	
	@Resource
	BudgetMainService budgetMainService;
	
	@Resource
	BudgetSubItemService budgetSubItemService;
	
	@Resource
	BudgetExecuteService budgetExecuteService;
	
	@Resource
	UrgentApplyService urgentApplyService;
	
	@Resource
	CapitalApplyService capitalApplyService;
	
	@Resource
	FinishApplyService finishApplyService;
	
	@Resource
	ProjectItemService projectItemService;
	
	@Resource
	BudgetItemService budgetItemService;
	
	@Resource
	QuantitiesService quantitiesService;
	
	@Resource
	GoodsService goodsService;
	
	@Resource
	GoodsCurrentService goodsCurrentService;
	
	@Resource
	NoticeService noticeService;
	
	@Resource
	FormService formService;
	
	@Value("${review_model_code}")
	private String model_code;
	
	@Value("${review_fail_result_model_code}")
	private String result_fail_model_code;
	
	@Value("review_success_result_model_code")
	private String result_success_model_code;
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
	
	SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分");
	
	@RequestMapping(value = "/reviewlist.do",method = RequestMethod.GET)
	@ResponseBody
	public DataGridData<Review> reviewlist(@RequestParam(value = "page", required = false) String page,
			@RequestParam(value = "rows", required = false) String rows){
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		int roleid = userInfo.getRoleid();
		DataGridData<Review> result = new DataGridData();
		Map<String,Object> map = new HashMap<>();
		PageBean pageBean = null;
		if (TextUtil.isNotEmpty(page) && TextUtil.isNotEmpty(rows)) {
			pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
		}
		if (pageBean != null) {
			map.put("start", pageBean.getStart());
			map.put("size", pageBean.getPageSize());
		}
		map.put("userid",userInfo.getId());
		map.put("companyid",userInfo.getCompanyid());
		if(roleid == 1 || roleid == 2){
			result.setRows(reviewService.findUnreviewedForLevel1(map));
			result.setTotal(reviewService.countUnreviewedForLevel1(map));
		}else if(roleid == 3){
			result.setRows(reviewService.findUnreviewedForLevel2(map));
			result.setTotal(reviewService.countUnreviewedForLevel2(map));
		}
		return result;
	}
	
	@SystemControllerLog(description = "审批主计划")
	@RequestMapping(value = "/reviewplanmain.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewPlanmain(@RequestParam(value = "id",required = true) int id,
			@RequestParam(value = "flg",required = true) Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		PlanMain main = planMainService.selectByPrimaryKey(id);
		List<Notice> notices = new ArrayList<>();
		ProjectItem projectItem = projectItemService.selectByPrimaryKey(main.getProjectitemid());
		if(userInfo.getRoleid() == 1 | userInfo.getRoleid() == 2){// 一级审核
			main.setLevel1reviewdate(new Date());
			main.setLevel1reviewerid(userInfo.getId());
			if(flg){
				main.setStatus(4);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),0,
							"项目：" + projectItem.getName() + " 主计划 " + main.getName() + " 审批通过",0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"主计划");
					sendSuccessReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),0,
							"项目：" + projectItem.getName() + " 主计划 " + main.getName() + " 审批通过",0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"主计划");
					sendSuccessReviewResult(user,data);
				}
			}else{
				main.setStatus(3);
				main.setReason(reason);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),1,
							"项目：" + projectItem.getName() + " 主计划 " + main.getName() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"主计划",reason);
					sendFailReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),1,
							"项目：" + projectItem.getName() + " 主计划 " + main.getName() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"主计划",reason);
					sendFailReviewResult(user,data);
				}
			}
		}
		if(userInfo.getRoleid() == 3){
			if(main.getStatus() != 7){
				main.setLevel2reviewdate(new Date());
				main.setLevel2reviewerid(userInfo.getId());
				if(flg){
					main.setStatus(7);
					JSONObject data = WechatUtil.setReviewData(projectItem.getName() + " 主计划",
							sdf2.format(main.getCreatedate()));
					sendReview(projectItem.getCreater(),data);
				}else{
					main.setStatus(3);
					main.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,
								"项目：" + projectItem.getName() + " 主计划 " + main.getName() + " 审批未通过<br>原因：" + reason,0,
								new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"主计划",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = planMainService.update(main);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批日计划")
	@RequestMapping(value = "/reviewplandaily.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewPlandaily(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		PlanDaily daily = planDailyService.selectByPrimaryKey(id);
		ProjectItem projectItem = projectItemService.selectByPrimaryKey(daily.getPlanMain().getProjectitemid());
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 3){
			if(daily.getStatus() != 7){
				daily.setLevel2reviewdate(new Date());
				daily.setLevel2reviewerid(userInfo.getId());
				if(flg){
					daily.setStatus(4);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),0,
								"项目：" + projectItem.getName() + " 日计划 " + sdf.format(daily.getPlandate()) + " 审批通过",0,
								new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"日计划");
						sendSuccessReviewResult(user,data);
					}
				}else{
					daily.setStatus(3);
					daily.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 日计划 "
								+ sdf.format(daily.getPlandate()) + " 审批未通过<br>原因：" + reason,0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"日计划",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = planDailyService.update(daily);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批工程量")
	@RequestMapping(value = "/reviewquantities.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewquantities(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		Quantities daily = quantitiesService.selectByPrimaryKey(id);
		ProjectItem projectItem = projectItemService.selectByPrimaryKey(daily.getProjectitemid());
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 3){
			if(daily.getStatus() != 7){
				daily.setLevel2reviewdate(new Date());
				daily.setLevel2reviewerid(userInfo.getId());
				if(flg){
					daily.setStatus(4);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),0,
								"项目：" + projectItem.getName() + " 工程量 " + sdf.format(daily.getCreatedate()) + " 审批通过",0,
								new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"工程量");
						sendSuccessReviewResult(user,data);
					}
				}else{
					daily.setStatus(3);
					daily.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 工程量 "
								+ sdf.format(daily.getCreatedate()) + " 审批未通过<br>原因：" + reason,0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"工程量",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = quantitiesService.update(daily);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批物资")
	@RequestMapping(value = "/reviewgoods.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewgoods(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		Goods daily = goodsService.selectByPrimaryKey(id);
		ProjectItem projectItem = projectItemService.selectByPrimaryKey(daily.getProjectitemid());
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 3){
			if(daily.getStatus() != 7){
				daily.setLevel2reviewdate(new Date());
				daily.setLevel2reviewerid(userInfo.getId());
				if(flg){
					daily.setStatus(4);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),0,
								"项目：" + projectItem.getName() + " 物资 " + sdf.format(daily.getCreatedate()) + " 审批通过",0,
								new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"物资");
						sendSuccessReviewResult(user,data);
					}
				}else{
					daily.setStatus(3);
					daily.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 物资 "
								+ sdf.format(daily.getCreatedate()) + " 审批未通过<br>原因：" + reason,0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"物资",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = goodsService.update(daily);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批物资流动")
	@RequestMapping(value = "/reviewgoodscurrent.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewgoodscurrent(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		GoodsCurrent daily = goodsCurrentService.selectByPrimaryKey(id);
		ProjectItem projectItem = projectItemService.selectByPrimaryKey(daily.getGoods().getProjectitemid());
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 3){
			if(daily.getStatus() != 7){
				daily.setLevel2reviewdate(new Date());
				daily.setLevel2reviewerid(userInfo.getId());
				if(flg){
					daily.setStatus(4);
					Goods goods = goodsService.selectByPrimaryKey(daily.getGoodsid());
					if(daily.getType()==1){
						String newEnds = String.valueOf(Integer.valueOf(goods.getEnds())+Integer.valueOf(daily.getDifference()));
						goods.setEnds(newEnds);
						goodsService.update(goods);
					}else if (daily.getType()==2) {
						String newEnds = String.valueOf(Integer.valueOf(goods.getEnds())-Integer.valueOf(daily.getDifference()));
						goods.setEnds(newEnds);
						goodsService.update(goods);
					}
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),0,
								"项目：" + projectItem.getName() + " 物资流动 " + sdf.format(daily.getCreatedate()) + " 审批通过",0,
								new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"物资流动");
						sendSuccessReviewResult(user,data);
					}
				}else{
					daily.setStatus(3);
					daily.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 物资流动 "
								+ sdf.format(daily.getCreatedate()) + " 审批未通过<br>原因：" + reason,0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"物资流动",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = goodsCurrentService.update(daily);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批预算")
	@RequestMapping(value = "/reviewbudgetmain.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewBudgetmain(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "money",required = false) String money,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		int count = 0;
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		BudgetSubItem subItem = budgetSubItemService.selectByPrimaryKey(id);
		ProjectItem projectItem = projectItemService.selectByPrimaryKey(subItem.getMain().getProjectitemid());
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 1 | userInfo.getRoleid() == 2){// 一级审核
			subItem.setLevel1reviewdate(new Date());
			subItem.setLevel1reviewerid(userInfo.getId());
			if(flg){
				subItem.setStatus(4);
				subItem.setMoney(money);
				count = budgetSubItemService.review(subItem);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 预算申请 "
							+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批通过",0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"预算申请");
					sendSuccessReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 预算申请 "
							+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批通过",0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"预算申请");
					sendSuccessReviewResult(user,data);
				}
			}else{
				subItem.setStatus(3);
				subItem.setReason(reason);
				count = budgetSubItemService.update(subItem);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 预算申请 "
							+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"预算申请",reason);
					sendFailReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 预算申请 "
							+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"预算申请",reason);
					sendFailReviewResult(user,data);
				}
			}
		}
		if(userInfo.getRoleid() == 3){
			if(subItem.getStatus() == 7){
				count = 1;
			}else{
				subItem.setLevel2reviewdate(new Date());
				subItem.setLevel2reviewerid(userInfo.getId());
			}
			if(flg){
				subItem.setMoney(money);
				if(Double.parseDouble(userInfo.getCompany().getLevel2money() == null?"0"
						:userInfo.getCompany().getLevel2money()) >= Double.parseDouble(subItem.getMoney())){
					subItem.setStatus(4);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 预算申请 "
								+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批通过",0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"预算申请");
						sendSuccessReviewResult(user,data);
					}
					Notice notice = new Notice(projectItem.getCreaterid(),0,"项目：" + projectItem.getName() + " 预算申请 "
							+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批通过",0,new Date());
					notices.add(notice);
				}else{
					subItem.setStatus(7);
					JSONObject data = WechatUtil.setReviewData(projectItem.getName() + " 预算申请",
							sdf2.format(subItem.getCreatedate()));
					sendReview(projectItem.getCreater(),data);
				}
			}else{
				subItem.setStatus(3);
				subItem.setReason(reason);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 预算申请 "
							+ subItem.getItem().getContent() + " " + subItem.getMoney() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"预算申请",reason);
					sendFailReviewResult(user,data);
				}
			}
			count = budgetSubItemService.update(subItem);
		}
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批预算执行")
	@RequestMapping(value = "/reviewbudgetexecute.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewBudgetexecute(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		BudgetExecute execute = budgetExecuteService.selectByPrimaryKey(id);
		ProjectItem projectItem = execute.getProjectItem();
		List<Notice> notices = new ArrayList<>();
		Map<String,Object> map = new HashMap<>();
		map.put("projectitemid",execute.getProjectitemid());
		map.put("budgetitemid",execute.getItemid());
		Map<String,Double> currentinfo = budgetItemService.getMoneySituation(map);
		double remain = Double.parseDouble(currentinfo.get("budgetmoney").toString())
				+ Double.parseDouble(currentinfo.get("applymoney").toString())
				- Double.parseDouble(currentinfo.get("executemoney").toString());
		if(userInfo.getRoleid() == 1 | userInfo.getRoleid() == 2){// 一级审核
			execute.setLevel1reviewdate(new Date());
			execute.setLevel1reviewerid(userInfo.getId());
			if(flg){
				if(remain >= Double.parseDouble(execute.getMoney())){
					execute.setStatus(4);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 预算执行 "
								+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批通过",0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"预算执行");
						sendSuccessReviewResult(user,data);
					}
					for(UserInfo user:projectItem.getLevel2()){
						Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 预算执行 "
								+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批通过",0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
								sdf2.format(new Date()),projectItem.getName(),"预算执行");
						sendSuccessReviewResult(user,data);
					}
				}else{
					result.setSuccess(false);
					result.setErrMsg("预算超支，当前" + execute.getItem().getContent() + "剩余金额：" + remain);
					return result;
				}
			}else{
				execute.setStatus(3);
				execute.setReason(reason);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 预算执行 "
							+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"预算执行",reason);
					sendFailReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 预算执行 "
							+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批未通过<br>原因：" + reason,0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"预算执行",reason);
					sendFailReviewResult(user,data);
				}
			}
		}
		if(userInfo.getRoleid() == 3){
			if(execute.getStatus() != 7){
				execute.setLevel2reviewdate(new Date());
				execute.setLevel2reviewerid(userInfo.getId());
				if(flg){
					if(remain >= Double.parseDouble(execute.getMoney())){
						if(Double.parseDouble(userInfo.getCompany().getLevel2money() == null?"0"
								:userInfo.getCompany().getLevel2money()) >= Double.parseDouble(execute.getMoney())){
							execute.setStatus(4);
							for(UserInfo user:projectItem.getLevel3()){
								Notice notice = new Notice(
										user.getId(),0,"项目：" + projectItem.getName() + " 预算执行 "
												+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批通过",
										0,new Date());
								notices.add(notice);
								JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
										sdf2.format(new Date()),projectItem.getName(),"预算执行");
								sendSuccessReviewResult(user,data);
							}
							Notice notice = new Notice(
									projectItem.getCreaterid(),0,"项目：" + projectItem.getName() + " 预算执行 "
											+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批通过",
									0,new Date());
							notices.add(notice);
						}else{
							execute.setStatus(7);
							JSONObject data = WechatUtil.setReviewData(projectItem.getName() + " 预算执行",
									sdf2.format(execute.getCreatedate()));
							sendReview(projectItem.getCreater(),data);
						}
					}else{
						result.setSuccess(false);
						result.setErrMsg("预算超支，当前" + execute.getItem().getContent() + "剩余金额：" + remain);
						return result;
					}
				}else{
					execute.setStatus(3);
					execute.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 预算执行 "
								+ execute.getItem().getContent() + " " + execute.getMoney() + " 审批未通过<br>原因：" + reason,
								0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"预算执行",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = budgetExecuteService.update(execute);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批特情申请")
	@RequestMapping(value = "/reviewurgentapply.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewUrgentApply(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		UrgentApply urgent = urgentApplyService.selectByPrimaryKey(id);
		ProjectItem projectItem = urgent.getItem();
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 1 | userInfo.getRoleid() == 2){// 一级审核
			urgent.setLevel1reviewdate(new Date());
			urgent.setLevel1reviewerid(userInfo.getId());
			if(flg){
				urgent.setStatus(4);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),0,
							"项目：" + projectItem.getName() + " 特情申请 " + sdf.format(urgent.getUrgentdate()) + " 审批通过",0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"特情申请");
					sendSuccessReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),0,
							"项目：" + projectItem.getName() + " 特情申请 " + sdf.format(urgent.getUrgentdate()) + " 审批通过",0,
							new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"特情申请");
					sendSuccessReviewResult(user,data);
				}
			}else{
				urgent.setStatus(3);
				urgent.setReason(reason);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 特情申请 "
							+ sdf.format(urgent.getUrgentdate()) + " 审批未通过<br>原因：" + reason,0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"特情申请 ",reason);
					sendFailReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 特情申请 "
							+ sdf.format(urgent.getUrgentdate()) + " 审批未通过<br>原因：" + reason,0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"特情申请 ",reason);
					sendFailReviewResult(user,data);
				}
			}
		}
		if(userInfo.getRoleid() == 3){
			if(urgent.getStatus() != 7){
				urgent.setLevel2reviewdate(new Date());
				urgent.setLevel2reviewerid(userInfo.getId());
				if(flg){
					urgent.setStatus(7);
					JSONObject data = WechatUtil.setReviewData(projectItem.getName() + " 特情申请",
							sdf2.format(urgent.getCreatedate()));
					sendReview(projectItem.getCreater(),data);
				}else{
					urgent.setStatus(3);
					urgent.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 特情申请 "
								+ sdf.format(urgent.getUrgentdate()) + " 审批未通过<br>原因：" + reason,0,new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"特情申请 ",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = urgentApplyService.update(urgent);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	
	@SystemControllerLog(description = "审批资金申请")
	@RequestMapping(value = "/reviewcapitalapply.do",method = RequestMethod.POST)
	@ResponseBody
	public OperateResult reviewCapitalApply(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
			@RequestParam(value = "reason",required = false) String reason){
		OperateResult result = new OperateResult();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		CapitalApply capital = capitalApplyService.selectByPrimaryKey(id);
		ProjectItem projectItem = capital.getItem();
		List<Notice> notices = new ArrayList<>();
		if(userInfo.getRoleid() == 1 | userInfo.getRoleid() == 2){// 一级审核
			capital.setLevel1reviewdate(new Date());
			capital.setLevel1reviewerid(userInfo.getId());
			if(flg){
				capital.setStatus(4);
				if(capital.getProjectitemchildid() != null){
					BudgetMain budgetMain = budgetMainService.searchbyprojectitemchild(capital.getProjectitemchildid());
					Double money = Double.valueOf(budgetMain.getMoney()) + Double.valueOf(capital.getMoney());
					budgetMain.setMoney(String.valueOf(money));
					budgetMainService.updateByPrimaryKeySelective(budgetMain);
					/*BudgetSubItem budgetSubItem = new BudgetSubItem();
					budgetSubItem.setMainid(budgetMain.getId());
					budgetSubItem.setItemid(capital.getBudgetitemid());
					budgetSubItem.setMoney(capital.getMoney());
					budgetSubItem.setContent("资金申请");
					budgetSubItem.setStatus(4);
					budgetSubItem.setCreatedate(new Date());
					budgetSubItemService.insert(budgetSubItem);*/
					BudgetMain budgetMain2 = budgetMainService.searchbyprojectitemid(capital.getProjectitemid());
					Double money2 = Double.valueOf(budgetMain2.getMoney()) + Double.valueOf(capital.getMoney());
					budgetMain2.setMoney(String.valueOf(money2));
					budgetMainService.updateByPrimaryKeySelective(budgetMain2);
				}else{
					BudgetMain budgetMain2 = budgetMainService.searchbyprojectitemid(capital.getProjectitemid());
					Double money2 = Double.valueOf(budgetMain2.getMoney()) + Double.valueOf(capital.getMoney());
					budgetMain2.setMoney(String.valueOf(money2));
					budgetMainService.updateByPrimaryKeySelective(budgetMain2);
					/*BudgetSubItem budgetSubItem = new BudgetSubItem();
					budgetSubItem.setMainid(budgetMain2.getId());
					budgetSubItem.setItemid(capital.getBudgetitemid());
					budgetSubItem.setMoney(capital.getMoney());
					budgetSubItem.setContent("资金申请");
					budgetSubItem.setStatus(4);
					budgetSubItem.setCreatedate(new Date());
					budgetSubItemService.insert(budgetSubItem);*/
				}
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 资金申请 "
							+ capital.getContent() + " " + capital.getMoney() + " 审批通过",0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"资金申请 ");
					sendSuccessReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 资金申请 "
							+ capital.getContent() + " " + capital.getMoney() + " 审批通过",0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
							sdf2.format(new Date()),projectItem.getName(),"资金申请 ");
					sendSuccessReviewResult(user,data);
				}
			}else{
				capital.setStatus(3);
				capital.setReason(reason);
				for(UserInfo user:projectItem.getLevel3()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 资金申请 "
							+ capital.getContent() + " " + capital.getMoney() + " 审批未通过<br>原因：" + reason,0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"资金申请  ",reason);
					sendFailReviewResult(user,data);
				}
				for(UserInfo user:projectItem.getLevel2()){
					Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 资金申请 "
							+ capital.getContent() + " " + capital.getMoney() + " 审批未通过<br>原因：" + reason,0,new Date());
					notices.add(notice);
					JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
							sdf2.format(new Date()),projectItem.getName(),"资金申请  ",reason);
					sendFailReviewResult(user,data);
				}
			}
		}
		if(userInfo.getRoleid() == 3){
			if(capital.getStatus() != 7){
				capital.setLevel2reviewdate(new Date());
				capital.setLevel2reviewerid(userInfo.getId());
				if(flg){
					if(Double.parseDouble(userInfo.getCompany().getLevel2money() == null?"0"
							:userInfo.getCompany().getLevel2money()) >= Double.parseDouble(capital.getMoney())){
						capital.setStatus(4);
						for(UserInfo user:projectItem.getLevel3()){
							Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 资金申请 "
									+ capital.getContent() + " " + capital.getMoney() + " 审批通过",0,new Date());
							notices.add(notice);
							JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过",
									sdf2.format(new Date()),projectItem.getName(),"预算申请");
							sendSuccessReviewResult(user,data);
						}
					}else{
						capital.setStatus(7);
						JSONObject data = WechatUtil.setReviewData(projectItem.getName() + " 资金申请",
								sdf2.format(capital.getCreatedate()));
						sendReview(projectItem.getCreater(),data);
					}
				}else{
					capital.setStatus(3);
					capital.setReason(reason);
					for(UserInfo user:projectItem.getLevel3()){
						Notice notice = new Notice(user.getId(),1,"项目：" + projectItem.getName() + " 资金申请 "
								+ capital.getContent() + " " + capital.getMoney() + " 审批未通过<br>原因：" + reason,0,
								new Date());
						notices.add(notice);
						JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
								sdf2.format(new Date()),projectItem.getName(),"资金申请  ",reason);
						sendFailReviewResult(user,data);
					}
				}
			}
		}
		int count = capitalApplyService.update(capital);
		for(Notice notice:notices){
			count += noticeService.insertSelective(notice);
		}
		result.setSuccess(count > 0);
		return result;
	}
	/*
	 * @SystemControllerLog(description = "审批竣工申请")
	 * @RequestMapping(value = "/reviewfinishapply.do",method = RequestMethod.POST)
	 * @ResponseBody public OperateResult reviewFinishApply(@RequestParam("id") int id,@RequestParam("flg") Boolean flg,
	 * @RequestParam(value = "reason",required = false) String reason){ OperateResult result = new OperateResult(); Subject currentUser =
	 * SecurityUtils.getSubject(); UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo"); FinishApply finish =
	 * finishApplyService.selectByPrimaryKey(id); ProjectItem projectItem = finish.getItem(); List<Notice> notices = new ArrayList<>();
	 * if(userInfo.getRoleid() == 1 | userInfo.getRoleid() == 2){// 一级审核 finish.setLevel1reviewdate(new Date());
	 * finish.setLevel1reviewerid(userInfo.getId()); if(flg){ finish.setStatus(4); ProjectItem item =
	 * projectItemService.selectByPrimaryKey(finish.getProjectitemid()); item.setStatus(5); projectItemService.updateByPrimaryKeySelective(item);
	 * for(UserInfo user:projectItem.getLevel3()){ Notice notice = new Notice(user.getId(),0,"项目：" + projectItem.getName() + " 竣工申请 " + " " + " 审批通过",
	 * 0,new Date()); notices.add(notice); JSONObject data = WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过", sdf2.format(new
	 * Date()),projectItem.getName(),"竣工申请 "); sendSuccessReviewResult(user,data); } for(UserInfo user:projectItem.getLevel2()){ Notice notice = new
	 * Notice(user.getId(),0,"项目：" + projectItem.getName() + " 竣工申请 " + " " + " 审批通过", 0,new Date()); notices.add(notice); JSONObject data =
	 * WechatUtil.setReviewSuccessResultData(userInfo.getName(),"审核通过", sdf2.format(new Date()),projectItem.getName(),"竣工申请 ");
	 * sendSuccessReviewResult(user,data); } }else{ finish.setStatus(3); finish.setReason(reason); for(UserInfo user:projectItem.getLevel3()){ Notice
	 * notice = new Notice(user.getId(),1, "项目：" + projectItem.getName() + " 竣工申请 " + " " + " 审批未通过<br>原因：" + reason,0,new Date());
	 * notices.add(notice); JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过", sdf2.format(new
	 * Date()),projectItem.getName(),"竣工申请 ",reason); sendFailReviewResult(user,data); } for(UserInfo user:projectItem.getLevel2()){ Notice notice =
	 * new Notice(user.getId(),1, "项目：" + projectItem.getName() + " 竣工申请 " + " " + " 审批未通过<br>原因：" + reason,0,new Date()); notices.add(notice);
	 * JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过", sdf2.format(new Date()),projectItem.getName(),"竣工申请 ",reason);
	 * sendFailReviewResult(user,data); } } } if(userInfo.getRoleid() == 3){ if(finish.getStatus() != 7){ finish.setLevel2reviewdate(new Date());
	 * finish.setLevel2reviewerid(userInfo.getId()); if(flg){ finish.setStatus(7); JSONObject data = WechatUtil.setReviewData(projectItem.getName() +
	 * " 竣工申请", sdf2.format(finish.getCreatedate())); sendReview(projectItem.getCreater(),data); }else{ finish.setStatus(3); finish.setReason(reason);
	 * for(UserInfo user:projectItem.getLevel3()){ Notice notice = new Notice(user.getId(),1, "项目：" + projectItem.getName() + " 竣工申请 " + " " +
	 * " 审批未通过<br>原因：" + reason,0,new Date()); notices.add(notice); JSONObject data = WechatUtil.setReviewFailResultData(userInfo.getName(),"审核未通过",
	 * sdf2.format(new Date()),projectItem.getName(),"竣工申请 ",reason); sendFailReviewResult(user,data); } } } } int count =
	 * finishApplyService.update(finish); result.setSuccess(count > 0); return result; }
	 */
	
	@RequestMapping(value = "/moneyinfo.do",method = RequestMethod.GET)
	@ResponseBody
	public List<Map<String,Object>> moneyinfo(@RequestParam("projectitemid") int projectitemid,
			@RequestParam(value = "monthdate",required = false) String monthdate){
		List<Map<String,Object>> list = new ArrayList<>();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("companyid",userInfo.getCompanyid());
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// 注意月份是MM
		Date date;
		try{
			if(TextUtil.isNotEmpty(monthdate)){
				date = simpleDateFormat.parse(monthdate);
				Calendar calendar = Calendar.getInstance(); // 创建Calendar 的实例
				calendar.setTime(date);
				calendar.add(Calendar.MONTH,-1);// 当前时间减去一个月，即一个月前的时间
				String fromdate = simpleDateFormat.format(calendar.getTime());
				Calendar calendar2 = Calendar.getInstance(); // 创建Calendar 的实例
				calendar2.setTime(date);
				String todate = simpleDateFormat.format(calendar2.getTime());
				map.put("fromdate",fromdate);
				map.put("todate",todate);
				map.put("projectitemid",projectitemid);
				list = reviewService.moneyinfo(map);
			}else{
				String fromdate = "2019-01-01";
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.DAY_OF_MONTH,+1);
				String todate = simpleDateFormat.format(calendar.getTime());
				map.put("fromdate",fromdate);
				map.put("todate",todate);
				map.put("projectitemid",projectitemid);
				list = reviewService.moneyinfo(map);
			}
		}
		catch(ParseException e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	@RequestMapping(value = "/moneyinfo2.do",method = RequestMethod.GET)
	@ResponseBody
	public List<Map<String,Object>> moneyinfo2(@RequestParam("projectitemid") int projectitemid,
			@RequestParam(value = "startdate",required = false) String startdate,
			@RequestParam(value = "enddate",required = false) String enddate){
		List<Map<String,Object>> list = new ArrayList<>();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("fromdate",startdate);
		map.put("todate",enddate);
		map.put("projectitemid",projectitemid);
		list = reviewService.moneyinfo(map);
		return list;
	}
	
	@RequestMapping(value = "/moneyinfoyear.do",method = RequestMethod.GET)
	@ResponseBody
	public List<Map<String,Object>> moneyinfoyear(
			@RequestParam(value = "projectitemid",required = false) Integer projectitemid,
			@RequestParam(value = "yeardate",required = false) String yeardate){
		List<Map<String,Object>> list = new ArrayList<>();
		Map<String,Object> map = new HashMap<String,Object>();
		if(projectitemid != null && projectitemid != 0){
			if(TextUtil.isNotEmpty(yeardate)){
				String fromdate = yeardate + "-01-01";
				String todate = yeardate + "-12-31";
				map.put("fromdate",fromdate);
				map.put("todate",todate);
				map.put("projectitemid",projectitemid);
				list = reviewService.moneyinfo(map);
			}else{
				Calendar calendar = Calendar.getInstance();
				yeardate = String.valueOf(calendar.get(Calendar.YEAR));
				String fromdate = yeardate + "-01-01";
				String todate = yeardate + "-12-31";
				map.put("fromdate",fromdate);
				map.put("todate",todate);
				map.put("projectitemid",projectitemid);
				list = reviewService.moneyinfo(map);
			}
		}else{
			Subject currentUser = SecurityUtils.getSubject();
			UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
			map.put("companyid",userInfo.getCompanyid());
			if(TextUtil.isNotEmpty(yeardate)){
				String fromdate = yeardate + "-01-01";
				String todate = yeardate + "-12-31";
				map.put("fromdate",fromdate);
				map.put("todate",todate);
				list = reviewService.moneyinfoyear(map);
			}else{
				list = reviewService.moneyinfoyear(map);
			}
		}
		return list;
	}
	
	@RequestMapping(value = "/moneyinfo3.do",method = RequestMethod.GET)
	@ResponseBody
	public List<Map<String,Object>> moneyinfo3(){
		Map<String,Object> map = new HashMap<String,Object>();
		List<Map<String,Object>> list = new ArrayList<>();
		Subject currentUser = SecurityUtils.getSubject();
		UserInfo userInfo = (UserInfo)currentUser.getSession().getAttribute("userInfo");
		List<ProjectItem> projectItems = projectItemService.searchByCompany(userInfo.getCompanyid());
		for(ProjectItem projectItem:projectItems){
			Double budgetmoney = 0.0;
			Double executemoney = 0.0;
			Double capitalmoney = 0.0;
			map.put("projectitemid",projectItem.getId());
			List<Map<String,Object>> list2 = reviewService.allsummary(map);
			Map<String,Object> map2 = new HashMap<>();
			for(int i = 0;i < list2.size();i++){
				budgetmoney += Double.valueOf(list2.get(i).get("budgetmoney1").toString());
				executemoney += Double.valueOf(list2.get(i).get("executemoney1").toString());
				capitalmoney += Double.valueOf(list2.get(i).get("capitalmoney1").toString());
			}
			map2.put("projectitem",projectItem);
			map2.put("budgetmoney1",budgetmoney);
			map2.put("executemoney1",executemoney);
			map2.put("capitalmoney1",capitalmoney);
			list.add(map2);
		}
		return list;
	}
	
	private void sendFailReviewResult(UserInfo userInfo,JSONObject data){
		List<Form> forms = formService.findbyuser(userInfo.getId());
		for(Form form:forms){
			String code = WechatUtil.pushMessage(userInfo.getOpenid(),result_fail_model_code,form.getFormid(),data);
			formService.deleteByPrimaryKey(form.getId());
			if(code == "0"){
				break;
			}
		}
	}
	
	private void sendSuccessReviewResult(UserInfo userInfo,JSONObject data){
		List<Form> forms = formService.findbyuser(userInfo.getId());
		for(Form form:forms){
			String code = WechatUtil.pushMessage(userInfo.getOpenid(),result_success_model_code,form.getFormid(),data);
			formService.deleteByPrimaryKey(form.getId());
			if(code == "0"){
				break;
			}
		}
	}
	
	private void sendReview(UserInfo userInfo,JSONObject data){
		List<Form> forms = formService.findbyuser(userInfo.getId());
		for(Form form:forms){
			String code = WechatUtil.pushMessage(userInfo.getOpenid(),model_code,form.getFormid(),data);
			formService.deleteByPrimaryKey(form.getId());
			if(code.trim().equals("0")){
				return;
			}
		}
	}
}
